package com.yuan.leet_note.linklist;

import com.yuan.leet_note.common.ListNode;

/**
 * @ClassName: ReverseLink
 * @Description: TODO
 * @Author MrYuan
 * @Date: 2021/6/28 16:02
 * @Version 1.0
 */
public class ReverseLink {

    //    {1,2,3}
//    {3,2,1}
    public static ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) return head;
        ListNode pre = null;
        ListNode next = null;
        while (head != null) {
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }
        return pre;
    }

    public static void main(String[] args) {
        ListNode listNode1 = new ListNode(1);
        ListNode listNode2 = new ListNode(2);
        ListNode listNode3 = new ListNode(3);
        listNode1.next = listNode2;
        listNode2.next = listNode3;
        ListNode head = reverseList(listNode1);
        System.out.println(head.val);
    }
}